package com.googlecode.maven.plugin.appassembler;

import com.googlecode.maven.plugin.appassembler.booter.classworlds.ClassworldsBooter;
import com.googlecode.maven.plugin.appassembler.booter.classworlds.ClassworldsBooterConfiguration;
import java.io.File;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Generates booter files.
 */
public final class BooterManager
    {
    /**
     * Constructs a new BooterManager object.
     */
    private BooterManager()
        {
        super();
        }

    /**
     * Generates booter files.
     *
     * @param configuration Booter configuration.
     * @param app Application.
     * @param targetDirectory Target directory.
     * @throws MojoFailureException If this operation failed.
     */
    public static void apply(BooterConfiguration booterConfiguration, App app,
            File targetDirectory)
            throws MojoFailureException
        {
        if (booterConfiguration == null)
            {
            return;
            }
        boolean booterConfigured = false;
        if (booterConfiguration.getClassworlds() != null)
            {
            if (booterConfigured)
                {
                throw new MojoFailureException("Multiple booters not allowed.");
                }
            ClassworldsBooterConfiguration classworldsBooterConfiguration = booterConfiguration.
                    getClassworlds();
            ClassworldsBooter.apply(classworldsBooterConfiguration, app,
                    targetDirectory);
            booterConfigured = true;
            }
        }
    }
